﻿using AutoMapper;
using MediatR;
using ZGLXM.ErrorCode;
using ZGLXM.Infra.Interface;
using ZGLXM.Infra.Repository;
using ZGLXM.Read.Api.Applicantion.Command.RBAC;

namespace ZGLXM.Read.Api.Applicantion.Handler.RBAC
{
    public class ProfessionByIdCommandHandler : IRequestHandler<ProfessionByIdCommand, ApiResult>
    {
        private readonly IProfessionRepository professionRepository;
        private readonly IMapper mapper;
        private readonly ILogger<ProfessionByIdCommandHandler> logger;
        public ProfessionByIdCommandHandler(IProfessionRepository professionRepository, IMapper mapper, ILogger<ProfessionByIdCommandHandler> logger)
        {
            this.professionRepository = professionRepository;
            this.mapper = mapper;
            this.logger = logger;
        }

        public async Task<ApiResult> Handle(ProfessionByIdCommand request, CancellationToken cancellationToken)
        {
            var profession = await professionRepository.GetAsync(x => x.ProfessionId == request.ProfessionId && x.IsDeleted == false);
            if (profession == null)
            {
                return ApiResult.Fail("信息不存在");
            }
            return ApiResult.OK(profession);
        }
    }
}
